/**
 * 
 */
package cn.ivicar.app.controller.vehicle;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.Inject;

import cn.com.carsmart.exception.BadRequestException;
import cn.com.carsmart.exception.CarsmartException;
import cn.com.carsmart.exception.InternalErrorException;
import cn.com.carsmart.ws.model.Customer;
import cn.com.carsmart.ws.model.CustomerVehicle;
import cn.com.carsmart.ws.model.Vehicle;
import cn.ivicar.app.controller.service.CustomerVehicleService;
import cn.ivicar.app.controller.service.RelationService;
import cn.ivicar.app.controller.service.VehicleService;
import cn.ivicar.passport.controller.PassportController;
import cn.ivicar.passport.controller.utils.PassportUtil;
import net.sf.json.JSONObject;

/**
 * @author liurunbin 2017年5月18日 cn.ivicar.app.controller.vehicle
 */
public class VehicleController {

	private static transient final Logger LOGGER = LoggerFactory.getLogger(VehicleController.class);

	@Inject
	private VehicleService vService;
	@Inject
	private CustomerVehicleService cvService;
	@Inject
	private PassportController passportController;
	@Inject
	private RelationService relationService;

	public JSONObject getVehicleInfo(Long vehicleId, Long customerId) throws CarsmartException {
		if (vehicleId == null || customerId == null) {
			throw new BadRequestException("400", "请求参数不能为空!");
		}
		JSONObject result = new JSONObject();
		CustomerVehicle cv = cvService.get(customerId, vehicleId);
		if (cv == null) {
			LOGGER.info(String.format("用户[customerId = %s]尚未关联车辆[vehicleId = %s]", customerId, vehicleId));
			throw new BadRequestException("400", "当前用户尚未关联这辆车");
		}

		Vehicle v = vService.get(vehicleId);
		if (v != null) {
			result.put("vehicleId", v.getId() + "");
			result.put("vehicleName", v.getName() == null ? "" : v.getName());
			result.put("vehicleSerial", v.getSerial() == null ? "" : v.getSerial());
			result.put("licensePlate", v.getLicensePlate() == null ? "" : v.getLicensePlate());
			result.put("vin", v.getVin() == null ? "" : v.getVin());
			result.put("ein", v.getEin() == null ? "" : v.getEin());
		}

		return result;
	}

	public void setVehicleInfo(Long vehicleId, JSONObject params, Long customerId) throws CarsmartException {

		if (vehicleId == null || customerId == null || params == null || params.isEmpty()) {
			throw new BadRequestException("400", "请求参数不能为空!");
		}

		CustomerVehicle cv = cvService.get(customerId, vehicleId);
		if (cv == null) {
			LOGGER.info(String.format("用户[customerId = %s]尚未关联车辆[vehicleId = %s]", customerId, vehicleId));
			throw new BadRequestException("400", "当前用户尚未关联这辆车");
		}

		if (!cv.getOwner()) {
			throw new BadRequestException("400", "您没有权限修改这辆车的信息");
		}

		Vehicle update = vService.get(vehicleId);
		String vehicleSerial = params.optString("vehicleSerial", update.getSerial());
		String licensePlate = params.optString("licensePlate", update.getLicensePlate());
		String ein = params.optString("ein", update.getEin());
		String vin = params.optString("vin", update.getVin());

		vehicleInfoValidate(vehicleId, update.getName(), vehicleSerial, licensePlate, ein, vin);

		// 唯一性验证
		if (StringUtils.isNotBlank(vehicleSerial)) {
			update.setSerial(vehicleSerial);
		}
		if (StringUtils.isNotBlank(licensePlate)) {
			update.setLicensePlate(licensePlate.toUpperCase());
		}
		if (StringUtils.isNotBlank(vin)) {
			update.setVin(vin);
		}
		if (StringUtils.isNotBlank(ein)) {
			update.setEin(ein);
		}

		try {
			vService.update(update);
		} catch (CarsmartException e) {
			LOGGER.warn(String.format("设置车辆[vehicleId=%s]信息失败", vehicleId), e);
			throw new BadRequestException("400", "设置车辆信息失败");
		} catch (Exception e) {
			LOGGER.error(String.format("设置车辆[vehicleId=%s]信息失败", vehicleId), e);
			throw new InternalErrorException("500", "设置车辆信息失败");
		}
	}

	private void vehicleInfoValidate(Long vehicleId, String vehicleName, String vehicleSerial, String licensePlate,
			String ein, String vin) throws BadRequestException {
		/*
		 * if ((StringUtils.isNotBlank(ein) && ein.length() > 20) ||
		 * (StringUtils.isNotBlank(ein) && ein.length() < 5)) { throw new
		 * BadRequestException("400", "发动机号码长度为5-20位!"); }
		 * 
		 * if (StringUtils.isNotBlank(vin) && vin.length() != 17) { throw new
		 * BadRequestException("400", "车辆识别代号为17位字符!"); }
		 */

		// TODO:待添加车辆信息长度校验
		if (StringUtils.isBlank(vehicleName)) {
			throw new BadRequestException("400", "请输入车辆名称!");
		}
		if (StringUtils.isBlank(vehicleSerial)) {
			throw new BadRequestException("400", "请输入设备序列号!");
		}
		if (StringUtils.isBlank(licensePlate)) {
			throw new BadRequestException("400", "请输入车牌号!");
		}

		// 唯一性验证
		if (StringUtils.isNotBlank(vehicleSerial)) {
			if (vService.validateVehicleByVehicleSerial(vehicleId, vehicleSerial)) {
				throw new BadRequestException("400", "设备序列号已存在!");
			}
		}

		// 唯一性验证
		if (StringUtils.isNotBlank(licensePlate)) {
			if (vService.validateVehicleByLicensePlate(vehicleId, licensePlate)) {
				throw new BadRequestException("400", "车牌号已存在!");
			}
		}
		if (StringUtils.isNotBlank(vin)) {
			if (vService.validateVehicleByVin(vehicleId, vin)) {
				throw new BadRequestException("400", "车辆识别代码已存在!");
			}
		}
		if (StringUtils.isNotBlank(ein)) {
			if (vService.validateVehicleByEin(vehicleId, ein)) {
				throw new BadRequestException("400", "发动机号码已存在!");
			}
		}
	}

	public void bind(Long customerId, JSONObject params) throws CarsmartException {
		if (customerId == null || params == null || params.isEmpty()) {
			throw new BadRequestException("400", "请求参数不能为空!");
		}

		String vehicleName = params.optString("vehicleName", null);
		String vehicleSerial = params.optString("vehicleSerial", null);
		String licensePlate = params.optString("licensePlate", null);
		String ein = params.optString("ein", null);
		String vin = params.optString("vin", null);
		if (StringUtils.isBlank(vehicleSerial)) {
			throw new BadRequestException("400", "请输入设备序列号!");
		}

		Long vId = null;
		Vehicle v = vService.getBySerial(vehicleSerial);
		if (v != null) {
			List<CustomerVehicle> list = cvService.getByVehicleId(v.getId(), true);
			if (list != null && !list.isEmpty()) {
				for (CustomerVehicle object : list) {
					if (object.getCustomerId().intValue() != customerId.intValue()) {
						throw new BadRequestException("400", "设备序列号已存在!");
					} else if (object.getCustomerId().intValue() == customerId.intValue()) {
						throw new BadRequestException("400", "已绑定！");
					}
				}
			}

			vehicleInfoValidate(v.getId(), vehicleName, vehicleSerial, licensePlate, ein, vin);
			updateV(vehicleName, vehicleSerial, licensePlate, ein, vin, v);
			vId = v.getId();
		} else {
			vehicleInfoValidate(null, vehicleName, vehicleSerial, licensePlate, ein, vin);
			Vehicle insert = inserV(vehicleName, vehicleSerial, licensePlate, ein, vin);
			vId = insert.getId();
		}

		inserCV(customerId, vehicleName, vehicleSerial, licensePlate, ein, vin, vId);

		return;
	}

	private void inserCV(Long customerId, String vehicleName, String vehicleSerial, String licensePlate, String ein,
			String vin, Long vId) throws BadRequestException, InternalErrorException {
		CustomerVehicle cv = new CustomerVehicle();
		cv.setCustomerId(customerId);
		cv.setVehicleId(vId);
		cv.setStatus(1);
		cv.setOwner(true);
		try {
			cvService.insert(cv);
		} catch (CarsmartException e) {
			LOGGER.warn(String.format(
					"创建人车关系[customerId=%s][vehicleId=%s][vehicleName=%s][vehicleSerial=%s][licensePlate=%s][ein=%s][vin=%s]失败",
					customerId, vId, vehicleName, vehicleSerial, licensePlate, ein, vin), e);
			throw new BadRequestException("400", "绑定失败");
		} catch (Exception e) {
			LOGGER.error(String.format(
					"创建人车关系[customerId=%s][vehicleId=%s][vehicleName=%s][vehicleSerial=%s][licensePlate=%s][ein=%s][vin=%s]失败",
					customerId, vId, vehicleName, vehicleSerial, licensePlate, ein, vin), e);
			throw new InternalErrorException("500", "绑定失败");
		}
	}

	private Vehicle inserV(String vehicleName, String vehicleSerial, String licensePlate, String ein, String vin)
			throws BadRequestException, InternalErrorException {
		Vehicle insert = new Vehicle();
		insert.setName(vehicleName);
		insert.setSerial(vehicleSerial);
		insert.setLicensePlate(StringUtils.isNotBlank(licensePlate) ? licensePlate.toUpperCase() : "");
		insert.setEin(ein);
		insert.setVin(vin);
		try {
			vService.insert(insert);
		} catch (CarsmartException e) {
			LOGGER.warn(String.format("创建车辆[vehicleName=%s][vehicleSerial=%s][licensePlate=%s][ein=%s][vin=%s]失败",
					vehicleName, vehicleSerial, licensePlate, ein, vin), e);
			throw new BadRequestException("400", "绑定失败");
		} catch (Exception e) {
			LOGGER.error(String.format("创建车辆[vehicleName=%s][vehicleSerial=%s][licensePlate=%s][ein=%s][vin=%s]失败",
					vehicleName, vehicleSerial, licensePlate, ein, vin), e);
			throw new InternalErrorException("500", "绑定失败");
		}
		return insert;
	}

	private void updateV(String vehicleName, String vehicleSerial, String licensePlate, String ein, String vin,
			Vehicle v) throws BadRequestException, InternalErrorException {
		v.setName(vehicleName);
		v.setSerial(vehicleSerial);
		v.setLicensePlate(StringUtils.isNotBlank(licensePlate) ? licensePlate.toUpperCase() : "");
		v.setEin(ein);
		v.setVin(vin);
		try {
			vService.update(v);
		} catch (CarsmartException e) {
			LOGGER.warn(String.format(
					"更新已有车辆[vehicleId=%s][vehicleName=%s][vehicleSerial=%s][licensePlate=%s][ein=%s][vin=%s]失败",
					v.getId(), vehicleName, vehicleSerial, licensePlate, ein, vin), e);
			throw new BadRequestException("400", "绑定失败");
		} catch (Exception e) {
			LOGGER.error(String.format("更新已有车辆[vehicleName=%s][vehicleSerial=%s][licensePlate=%s][ein=%s][vin=%s]失败",
					v.getId(), vehicleName, vehicleSerial, licensePlate, ein, vin), e);
			throw new InternalErrorException("500", "绑定失败");
		}
	}

	public void unbind(Long customerId, Long vehicleId) throws CarsmartException {
		if (vehicleId == null || customerId == null) {
			throw new BadRequestException("400", "请求参数不能为空!");
		}

		CustomerVehicle cv = cvService.get(customerId, vehicleId);
		if (cv == null) {
			LOGGER.info(String.format("用户[customerId = %s]尚未关联车辆[vehicleId = %s]", customerId, vehicleId));
			throw new BadRequestException("400", "当前用户尚未关联这辆车");
		}

		if (!cv.getOwner()) {
			throw new BadRequestException("400", "您没有权限解绑这辆车");
		}

		try {
			cvService.deleteByVehicleId(vehicleId);
		} catch (CarsmartException e) {
			LOGGER.warn(String.format("解绑车辆[vehicleId=%s]失败", vehicleId), e);
			throw new BadRequestException("400", "解绑失败");
		} catch (Exception e) {
			LOGGER.error(String.format("解绑车辆[vehicleId=%s]失败", vehicleId), e);
			throw new InternalErrorException("500", "解绑失败");
		}

		try {
			vService.delete(vehicleId);
		} catch (CarsmartException e) {
			LOGGER.warn(String.format("删除车辆[vehicleId=%s]失败", vehicleId), e);
		} catch (Exception e) {
			LOGGER.error(String.format("删除车辆[vehicleId=%s]失败", vehicleId), e);
		}

	}

	/**
	 * 请求绑定车辆列表
	 */
	public JSONObject getBindVehicleList(Long customerId) throws CarsmartException {
		if (customerId == null) {
			throw new BadRequestException("400", "请求参数不能为空!");
		}
		JSONObject result = getBindsVehicleArrayByCId(customerId);
		return result;
	}

	/**
	 * 车辆共享
	 */
	public void share(Long customerId, Long vehicleId, JSONObject params) throws CarsmartException {
		if (vehicleId == null || customerId == null || params == null || params.isEmpty()) {
			throw new BadRequestException("400", "请求参数不能为空!");
		}

		CustomerVehicle cv = cvService.get(customerId, vehicleId);
		if (cv == null) {
			LOGGER.info(String.format("用户[customerId = %s]尚未关联车辆[vehicleId = %s]", customerId, vehicleId));
			throw new BadRequestException("400", "当前用户尚未关联这辆车");
		}

		if (!cv.getOwner()) {
			throw new BadRequestException("400", "您没有权限分享这辆车");
		}

		String mobile = params.optString("mobile", null);
		if (StringUtils.isBlank(mobile)) {
			throw new BadRequestException("400", "请输入小伙伴的手机号");
		}

		if (!PassportUtil.validateMobile(mobile)) {
			throw new BadRequestException("400", "手机号格式不正确");
		}

		Customer customer = passportController.getByMobile(mobile);
		if (customer == null) {
			LOGGER.info(String.format("手机号[mobile = %s]尚未注册，终止分享", mobile));
			// TODO:如果被分享者手机号未注册，要如何提示？现不做任何处理
			return;
		}
		
		CustomerVehicle ret = cvService.get(customer.getId(), vehicleId);
		if (ret != null) {
			LOGGER.info(String.format("用户[customerId = %s]已经将车辆[vehicleId = %s]分享给[mobile = %s]", customerId, vehicleId,mobile));
			throw new BadRequestException("400", "已分享！");
		}
		

		CustomerVehicle insert = new CustomerVehicle();
		insert.setCustomerId(customer.getId());
		insert.setVehicleId(vehicleId);
		insert.setOwner(false);
		insert.setStatus(1);
		try {
			cvService.insert(insert);
		} catch (CarsmartException e) {
			LOGGER.warn(
					String.format("用户[customerId=%s]分享车辆[vehicleId=%s]给[mobile=%s]失败", customerId, vehicleId, mobile),
					e);
			throw new BadRequestException("400", "分享失败");
		} catch (Exception e) {
			LOGGER.error(
					String.format("用户[customerId=%s]分享车辆[vehicleId=%s]给[mobile=%s]失败", customerId, vehicleId, mobile),
					e);
			throw new InternalErrorException("500", "分享失败");
		}

	}

	/**
	 * 解除车辆共享
	 */
	public void unVehicleshare(Long customerId, Long vehicleId, JSONObject params) throws CarsmartException {
		if (vehicleId == null || customerId == null || params == null || params.isEmpty()) {
			throw new BadRequestException("400", "请求参数不能为空!");
		}

		CustomerVehicle ownercv = cvService.get(customerId, vehicleId);
		if (ownercv == null) {
			LOGGER.info(String.format("用户[customerId = %s]尚未关联车辆[vehicleId = %s]", customerId, vehicleId));
			throw new BadRequestException("400", "当前用户尚未关联这辆车");
		}

		if (!ownercv.getOwner()) {
			throw new BadRequestException("400", "您没有权限权限解除这辆车的共享");
		}

		Long userId = params.optLong("userId", 0l);
		if (userId == null || userId.intValue() == 0) {
			throw new BadRequestException("400", "请求参数userId不能为空!");
		}

		CustomerVehicle sharedcv = cvService.get(userId, vehicleId);
		if (sharedcv == null) {
			LOGGER.warn(String.format("被分享用户[userId = %s]尚未关联车辆[vehicleId = %s],终止处理", userId, vehicleId));
			return;
		}

		try {
			cvService.deleteByCV(userId, vehicleId);
		} catch (CarsmartException e) {
			LOGGER.warn(String.format("车辆[vehicleId=%s]owner[customerId=%s]解除给用户[userId=%s]的分享失败", vehicleId,
					customerId, userId), e);
			throw new BadRequestException("400", "解除车辆共享失败");
		} catch (Exception e) {
			LOGGER.error(String.format("车辆[vehicleId=%s]owner[customerId=%s]解除给用户[userId=%s]的分享失败", vehicleId,
					customerId, userId), e);
			throw new InternalErrorException("500", "解除车辆共享失败");
		}

	}

	/**
	 * 解除用户共享
	 */
	public void unUsershare(Long customerId, Long vehicleId) throws CarsmartException {
		if (vehicleId == null || customerId == null) {
			throw new BadRequestException("400", "请求参数不能为空!");
		}

		CustomerVehicle ownercv = cvService.get(customerId, vehicleId);
		if (ownercv == null) {
			LOGGER.info(String.format("用户[customerId = %s]尚未关联车辆[vehicleId = %s]", customerId, vehicleId));
			throw new BadRequestException("400", "当前用户尚未关联这辆车");
		}
		if (ownercv.getOwner()) {
			// TODO:解除用户共享时，如果解除共享车辆的owner就是当前用户，该如何处理，现不做任何处理。
			return;
		}

		try {
			cvService.deleteByCV(customerId, vehicleId);
		} catch (CarsmartException e) {
			LOGGER.warn(String.format("用户[customerId=%s]主动解除分享给自己的车辆[vehicleId=%s]失败", customerId, vehicleId), e);
			throw new BadRequestException("400", "解除用户共享失败");
		} catch (Exception e) {
			LOGGER.error(String.format("用户[customerId=%s]主动解除分享给自己的车辆[vehicleId=%s]失败", customerId, vehicleId), e);
			throw new InternalErrorException("500", "解除用户共享失败");
		}

	}

	/**
	 * 请求用户共享车辆列表
	 */
	public JSONObject getUsershareVehicleList(Long customerId) throws CarsmartException {
		if (customerId == null) {
			throw new BadRequestException("400", "请求参数不能为空!");
		}
		
		//获取用户绑定车辆的分享信息
		boolean owner = true;
		JSONObject result = getVehicleArrayByCId(customerId, owner);

		return result;
	}
	
	private JSONObject getBindsVehicleArrayByCId(Long customerId) {
		JSONObject result = new JSONObject();
		result.put("items", "[]");
		result.put("count", "0");
		List<CustomerVehicle> ownerList = cvService.getByCustomerId(customerId, true);

		if (ownerList == null || ownerList.isEmpty()) {
			return result;
		}

		List<Long> vList = new ArrayList<Long>();
		for (CustomerVehicle cv : ownerList) {
			vList.add(cv.getVehicleId());
		}

		List<CustomerVehicle> noOwnerList = cvService.getByVIdList(vList, false);

		Map<Long, Integer> map = new HashMap<Long, Integer>();
		List<Long> vidList = new ArrayList<Long>();
		if (noOwnerList != null) {
			for (CustomerVehicle cv : noOwnerList) {
				vidList.add(cv.getVehicleId());
				Integer count = map.get(cv.getVehicleId());
				if (count == null) {
					map.put(cv.getVehicleId(), 1);
				} else {
					map.put(cv.getVehicleId(), ++count);
				}
				
			}
		}

		List<JSONObject> items = new ArrayList<JSONObject>();
		List<Vehicle> list = vService.get(vList);
		for (Vehicle v : list) {
			JSONObject item = new JSONObject();
			item.put("vehicleId", v.getId() + "");
			item.put("vehicleName", v.getName() == null ? "" : v.getName());
			item.put("vehicleSerial", v.getSerial() == null ? "" : v.getSerial());
			item.put("licensePlate", v.getLicensePlate() == null ? "" : v.getLicensePlate());
			item.put("vin", v.getVin() == null ? "" : v.getVin());
			item.put("ein", v.getEin() == null ? "" : v.getEin());
			item.put("shareTime", v.getCreated() == null ? "" : v.getCreated().getTime() + "");
			item.put("bindTime", v.getCreated() == null ? "" : v.getCreated().getTime() + "");
			item.put("shareUsers", map.get(v.getId()) == null ? "0" : map.get(v.getId()));
			String iccid = relationService.getIccid(v.getId());
			item.put("iccid", iccid == null ? "" : iccid);
			items.add(item);
		}
		result.put("items", items);
		result.put("count", items.size() + "");
		return result;
	}

	private JSONObject getVehicleArrayByCId(Long customerId, Boolean owner) {
		JSONObject result = new JSONObject();
		result.put("items", "[]");
		result.put("count", "0");
		List<CustomerVehicle> ownerList = cvService.getByCustomerId(customerId, owner);

		if (ownerList == null || ownerList.isEmpty()) {
			return result;
		}

		List<Long> vList = new ArrayList<Long>();
		for (CustomerVehicle cv : ownerList) {
			vList.add(cv.getVehicleId());
		}

		List<CustomerVehicle> noOwnerList = cvService.getByVIdList(vList, false);

		if (noOwnerList == null) {
			return result;
		}
		
		Map<Long, Integer> map = new HashMap<Long, Integer>();
		List<Long> vidList = new ArrayList<Long>();
		for (CustomerVehicle cv : noOwnerList) {
			vidList.add(cv.getVehicleId());
			Integer count = map.get(cv.getVehicleId());
			if (count == null) {
				map.put(cv.getVehicleId(), 1);
			} else {
				map.put(cv.getVehicleId(), ++count);
			}
			
		}

		List<JSONObject> items = new ArrayList<JSONObject>();
		List<Vehicle> list = vService.get(vList);
		for (Vehicle v : list) {
			JSONObject item = new JSONObject();
			item.put("vehicleId", v.getId() + "");
			item.put("vehicleName", v.getName() == null ? "" : v.getName());
			item.put("vehicleSerial", v.getSerial() == null ? "" : v.getSerial());
			item.put("licensePlate", v.getLicensePlate() == null ? "" : v.getLicensePlate());
			item.put("vin", v.getVin() == null ? "" : v.getVin());
			item.put("ein", v.getEin() == null ? "" : v.getEin());
			item.put("shareTime", v.getCreated() == null ? "" : v.getCreated().getTime() + "");
			item.put("bindTime", v.getCreated() == null ? "" : v.getCreated().getTime() + "");
			item.put("shareUsers", map.get(v.getId()) == null ? "0" : map.get(v.getId()));
			String iccid = relationService.getIccid(v.getId());
			item.put("iccid", iccid == null ? "" : iccid);
			items.add(item);
		}
		result.put("items", items);
		result.put("count", items.size() + "");
		return result;
	}

	private JSONObject getCustomerArrayByVId(Long vehicleId, Boolean owner) {
		JSONObject result = new JSONObject();
		result.put("items", "[]");
		result.put("count", "0");
		List<CustomerVehicle> ownerList = cvService.getByVehicleId(vehicleId, owner);

		if (ownerList == null || ownerList.isEmpty()) {
			return result;
		}

		Map<Long, Integer> map = new HashMap<Long, Integer>();
		List<Long> cidList = new ArrayList<Long>();
		for (CustomerVehicle cv : ownerList) {
			cidList.add(cv.getCustomerId());
			Integer count = map.get(cv.getCustomerId());
			if (count == null) {
				map.put(cv.getCustomerId(), 1);
			} else {
				map.put(cv.getCustomerId(), ++count);
			}

		}

		List<JSONObject> items = new ArrayList<JSONObject>();
		List<Customer> list = passportController.get(cidList);
		for (Customer c : list) {
			JSONObject item = new JSONObject();
			item.put("userId", c.getId() + "");
			item.put("mobile", c.getMobile() == null ? "" : c.getMobile());
			item.put("nickname", c.getNickname() == null ? "" : c.getNickname());
			item.put("shareUsers", map.get(c.getId()) == null ? "0" : map.get(c.getId()));
			items.add(item);

		}

		result.put("items", items);
		result.put("count", items.size() + "");
		return result;
	}

	public JSONObject getVehicleShareList(Long vehicleId, Long customerId) throws CarsmartException {
		if (vehicleId == null || customerId == null) {
			throw new BadRequestException("400", "请求参数不能为空!");
		}
		boolean owner = false;
		JSONObject result = this.getCustomerArrayByVId(vehicleId, owner);
		return result;
	}

	/**
	 * 请求被分享车辆列表
	 */
	public JSONObject getSharedVehicleList(Long customerId) throws CarsmartException {
		if (customerId == null) {
			throw new BadRequestException("400", "请求参数不能为空!");
		}
		JSONObject result = getVehicleArrayByCId(customerId, false);
		return result;
	}

}
